//
//  HMMusicTool.m
//  MymusicPlayer
//
//  Created by 陈尚飞 on 15/11/27.
//  Copyright © 2015年 陈尚飞. All rights reserved.
//

#import "HMMusicTool.h"
#import "HMMusicModel.h"
#import "MJExtension.h"


@implementation HMMusicTool

static NSArray * _musics;
static HMMusicModel *_playingMusic;
+ (void)initialize {
    _musics = [HMMusicModel objectArrayWithFilename:@"Musics.plist"];

}

+ (NSArray *)musics {

    return _musics;
}

+ (HMMusicModel *)playingMusic {
    return _playingMusic;
}

+ (void)setPlayingMusic:(HMMusicModel *)playingMusic {
    
    assert(playingMusic);
    _playingMusic = playingMusic;
    

}
+ (HMMusicModel *)nextMusic {
    //1.获取当前正在播放的音乐
    NSInteger currentIndex = [_musics indexOfObject:_playingMusic];
    
    //2.获取下一首音乐
    //2.1 索引加1
    currentIndex++;
    //2.2判断是否越界
    if (currentIndex > _musics.count - 1) {
    
        currentIndex = 0;
    
    }
    //2.3取出下一首音乐
    
    HMMusicModel *nextMusic = _musics[currentIndex];
    
    _playingMusic = nextMusic;
    
    return nextMusic;
    
}
+ (HMMusicModel *)previousMusic {
    //1.获取当前正在播放的音乐
    NSInteger currentIndex = [_musics indexOfObject:_playingMusic];
    
    //2.获取上一首音乐
    //2.1 索引加1
    currentIndex--;
    //2.2判断是否越界
    if (currentIndex < 0) {
        
        currentIndex = _musics.count - 1;
        
    }
    //2.3取出下一首音乐
    
    HMMusicModel *previousMusic = _musics[currentIndex];
    
    _playingMusic = previousMusic;
    
    return previousMusic;

}

@end
